"""
#!!===========================================================
#版权（C）2023, Huawei Technologies Co., HUTAF xDevice
#!!===========================================================
#用例编号:     Security_IAM_AuthWidget_Pin_Auth_Func_0004
#用例名称:      6位数字认证失败口令被锁定取消认证
#用例作者:
#修改说明:
#!!===========================================================
"""

# -*- coding: utf-8 -*-
from devicetest.core.test_case import TestCase
from devicetest.aw.OpenHarmony import CommonOH
from aw.Useriam.PinAuth import SecurityUserIamPinAuthApi
from aw.Useriam.AuthWidget import SecurityUserIamAuthWidgetPinAuth
from aw.Useriam.AuthWidget import SecurityUserIamAuthWidgetHapApi


class Security_IAM_AuthWidget_Pin_Auth_Func_0004(TestCase):

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        self.tests = [
            "test_step1",
        ]
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        print("预置工作：初始化手机开始............" + self.devices[0].device_sn)
        print("预置工作：设置6位口令为123456............")
        CommonOH.wake(self.device1)
        SecurityUserIamPinAuthApi.setPIN(self.device1, "123456")
        CommonOH.goHome(self.device1)
        print("预置工作：认证失败4次............")
        SecurityUserIamAuthWidgetHapApi.setAPI(self.device1, 3)
        SecurityUserIamAuthWidgetHapApi.setAuthType(self.device1, "1", "10000", "口令认证", " ", "1")
        SecurityUserIamAuthWidgetHapApi.auth(self.device1, 0)
        SecurityUserIamAuthWidgetPinAuth.PinAuth(self.device1, "113456", 0)
        SecurityUserIamAuthWidgetPinAuth.PinAuth(self.device1, "113456", 0)
        SecurityUserIamAuthWidgetPinAuth.PinAuth(self.device1, "113456", 0)
        SecurityUserIamAuthWidgetPinAuth.PinAuth(self.device1, "113456", 0)
        CommonOH.goHome(self.device1)

    def test_step1(self):
        print("测试步骤1：测试hap拉起口令认证")
        SecurityUserIamAuthWidgetHapApi.setAPI(self.device1, 3)
        SecurityUserIamAuthWidgetHapApi.setAuthType(self.device1, "1", "10000", "口令认证", "", "1")
        SecurityUserIamAuthWidgetHapApi.auth(self.device1, 0)
        print("测试步骤2：使用错误口令认证")
        SecurityUserIamAuthWidgetPinAuth.PinAuth(self.device1, "113456", 0)
        print("检查点2：认证锁定，控件存在")
        CommonOH.checkIfTextExist(self.device1, "失败次数过多", expect=True)
        print("测试步骤3：取消6位口令认证")
        SecurityUserIamAuthWidgetPinAuth.CancelAuth(self.device1)
        print("检查点3：控件退出")
        CommonOH.checkIfTextExist(self.device1, "失败次数过多", expect=False)
        CommonOH.wait(self.device1, 60)

    def teardown(self):
        print("收尾工作：删除口令............")
        SecurityUserIamPinAuthApi.deletePIN(self.device1, "123456", 0)
        print("收尾工作：口令已删除............")
        CommonOH.checkIfTextExist(self.device1, "关闭锁屏密码", expect=False)
        print("收尾工作：回到桌面............")
        CommonOH.goHome(self.device1)
